/**
 * create by young (young2f@outlook.com) on 2023/7/23
 */
'use strict';
const emq = require('mqtt');
const url = 'tcp://www.iotmqtt.cn';
const port = 21883;

const qos = 0;
const opts = {port, qos};
this.mqtt = emq.connect(url, opts);
this.mqtt.on('connect', packet => {

        this.mqtt.subscribe('/DEVICE/BASE/UPDATE/RICHTECH/BGX3688_SPEC/BGXY3688', err => {
            if (err === null || err === undefined) {
                this.app.logger.info('mqtt subscribe ok', topic);
            } else {
                this.app.logger.error('mqtt subscribe error', err);
            }
        });

});

/**
 * mqtt订阅消息到达
 */
this.mqtt.on('message', (topic, message) => {
    console.log('MQTT消息到达', message);
    // const json = _stringUtils.buffer2json(message);
    // this.app.eventBus.emit(topic, json);
});
